import Vue from 'vue'

import VueRouter from 'vue-router';

import routes from './router.config';

import Com404 from '@/views/404'

console.log(Com404)

// import Look from '@/views/look'

//import() promise对象

// console.log(import('@/views/listen'))

// import('@/views/listen').then(res => {
//     console.log(res);
// })

Vue.use(VueRouter);

/*
install(Vue,options){
    Vue.component('router-link',{})

    Vue.component('router-view',{)
}
**/

let router = new  VueRouter({
    mode:'history', //history hash  路由的原理  onhashchange
    routes:[
        ...routes,
        {
            path:'/404',
            component:() => import('@/views/404')
        },
        {
            path:'*',
            component:() => import('@/views/404')
        }
    ],
    linkActiveClass:'active'
})

//路由守卫

//1.全局守卫 2.组件内守卫  3.路由内守卫

router.beforeEach((to,from,next) => {
    console.log(to,from);
    document.title = to.matched[0].meta.title || '宝宝说';
    next();
})  

export {routes}
export default router